import 'package:extended_tabs/extended_tabs.dart';
import 'package:flutter/material.dart';
import 'package:live_music/pages/topic/page_view/topic_list.dart';
import 'package:live_music/utils/colors.dart';

class TopicIndexPage extends StatefulWidget {
  const TopicIndexPage({Key key}) : super(key: key);

  @override
  State<TopicIndexPage> createState() => _TopicIndexPageState();
}

class _TopicIndexPageState extends State<TopicIndexPage>
    with SingleTickerProviderStateMixin {
  TabController _tabController;
  final List<Widget> _tabsContent = [
    TopicListPage(type: 1),
    TopicListPage(type: 2)
  ];
  final List<Widget> _tabs = [Text('最新话题'), Text('热门话题')];
  @override
  void initState() {
    super.initState();
    _tabController = TabController(
      initialIndex: 1,
      length: _tabs.length,
      vsync: this,
    );
  }

  @override
  Widget build(BuildContext context) {
    double screenWidth = MediaQuery.of(context).size.width;
    return Scaffold(
        resizeToAvoidBottomInset: false,
        appBar: AppBar(
          centerTitle: true,
          title: Container(
              width: 0.55 * screenWidth,
              child: ExtendedTabBar(
                indicatorSize: TabBarIndicatorSize.label,
                controller: _tabController,
                indicatorColor: ColorRes.tabLine,
                indicatorWeight: 2,
                unselectedLabelStyle: TextStyle(
                    color: Colors.grey[600], // 下划线颜色
                    fontSize: 14,
                    fontWeight: FontWeight.w600),
                labelStyle: TextStyle(
                    color: Colors.white,
                    fontSize: 15,
                    fontWeight: FontWeight.w700), //标签文字大小颜色
                tabs: _tabs,
              )),
        ),
        body: Container(
          color: Colors.white,
          child: ExtendedTabBarView(
            controller: _tabController,
            children: _tabsContent,
          ),
        ));
  }
}
